package com.zmn.oms.admin.controller.work.modify;

import com.alibaba.nacos.api.config.annotation.NacosValue;
import com.zmn.common.utils.number.NumberUtil;
import com.zmn.common.utils.string.StringUtil;
import com.zmn.oms.admin.controller.work.WorkBaseController;
import com.zmn.oms.business.interfaces.orderstock.OrderStockBService;
import com.zmn.oms.common.dto.ResultDTO;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.Arrays;
import java.util.List;

/**
 * @ClassName WorkStockController
 * @description:
 * @author: wangyanci
 * @create: 2021-11-09 16:29
 * @Version 1.0
 **/
@Slf4j
@Controller
@RequestMapping("/work/stock")
public class WorkStockController extends WorkBaseController {

    @NacosValue(value = "${place.order.stock.city}", autoRefreshed = true)
    private String stockCity;

    /**
     * 检查城市是否开通库存试点
     */
    @RequestMapping(value = "/checkCityIsWhiteCity")
    @ResponseBody
    public ResultDTO checkCityIsWhiteCity(Integer cityId){

        return ResultDTO.success(this.isWhiteWorkCity(cityId));
    }

    private boolean isWhiteWorkCity(Integer cityId) {
        if (NumberUtil.isNullOrZero(cityId)) {
            return false;
        }
        if (StringUtil.isBlank(stockCity)) {
            return true;
        }
        List<String> strings = Arrays.asList(stockCity.split(","));
        return strings.contains(String.valueOf(cityId));
    }
}